package setting

import (
	logs2 "eat-every-day/pkg/logs"
	"github.com/spf13/viper"
)

type Setting struct {
	vp *viper.Viper
}

func NewSetting() (*Setting, error) {
	vp := viper.New()
	vp.SetConfigName("config")
	vp.AddConfigPath("configs/")
	vp.SetConfigType("yaml")
	err := vp.ReadInConfig()
	if err != nil {
		logs2.Log.Error("读取配置文件错误！", err)
		return nil, err
	}

	//viper.WatchConfig()
	//viper.OnConfigChange(func(e fsnotify.Event) {
	//	fmt.Printf("Config file changed: %s", e.Name)
	//})

	return &Setting{vp: vp}, nil
}
